// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// s [author] rhyme_lph
// H [email]  rhymelph@gmail.com
// k [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/entities/transaction_entity.dart';
import 'package:finance_app/src/mixin/filter_transaction_sort_mixin.dart';
import 'package:finance_app/src/mixin/refresh_mixin.dart';
import 'package:finance_app/src/mixin/time_sort_mixin.dart';
import 'package:finance_app/src/mixin/transaction_data_mixin.dart';
import 'package:finance_app/src/provider/dashboard/contact/business_contact_detail_provider.dart';
import 'package:finance_app/src/router_gen/router_gen_providers.dart';

class ContactDetailTransactionProvider extends BaseProvider
    with
        TimeSortMixin,
        FilterTransactionSortMixin,
        TransactionDataMixin,
        RefreshMixin<dynamic, List<TransactionEntity>> {
  @override
  Future get dataFuture => null;

  @override
  int get contactId => getParentProvider<BusinessContactDetailProvider>().id;

  @override
  List<String> get types => [
        'quotation',
        'invoice',
        'cash_in',
        'purchase_order',
        'bill',
        'expense',
        'cash_out'
      ];

  @override
  void unFocus() {}

  void onNavViewAll() {
    Routes.navigateTo(RouterGenProviders.allTransactionsPage, params: {
      'contactId': contactId,
      'type': 7,
    });
  }

  @override
  Future<void> onRefresh() async {
    getParentProvider<BusinessContactDetailProvider>().loadDashBoard();
    super.onRefresh();
  }

  void onTransactionDeleted() {
    onRefresh();
  }

  @override
  void onBackTransactionDetail() {
    getParentProvider<BusinessContactDetailProvider>().loadDashBoard();
  }

  @override
  List<TransactionEntity> get dataList => transactionList;
}
